
	jmp spriteshow

sprtab
	.byte 32,52,72,92,112,132,0

sprusd
	.byte 0	; 0..5

sprw8	.byte 5


spriteshow

if debug = 1
	inc $d020
eif

	lda $d011
	eor #16
	sta $d011

	lda #$2		; $4000-7fff bank
	sta $dd00

;	lda #$a0 	; 2800 / 0000 : char / videoram
			; start @ 6800
			
	lda #$ac 	; 2800 / 3000
	sta $d018

	
	lda #0
	sta sprusd


	lda #$ff
	sta $d015
	
	lda $d011
	ora #8
	sta $d011	; 24-lines mode

	ldx #0
_aax	lda #$07
	sta $d800,x
	sta $d900,x	
	lda #13
	sta $da00,x
	sta $db00,x
	dex
	bne _aax
	
	jsr scrollsetup
	jsr scrollsetup2

	
	sei

kupab	lda $d012
	cmp #$f0
	bne kupab
	
	
	lda $d011
	eor #16
	sta $d011

	

	lda #<irqs1
	ldy #>irqs1
	sta $0314
	sty $0315

	lda #30
	sta $D012

	lda $d011
	and #127
	sta $d011

	cli




	jmp _exxit

; prepare scrolltext

scrollsetup	
	lda #<stext
	ldx #>stext
	sta $b4
	stx $b5
	rts

scrollsetup2
	lda #<upstext
	ldx #>upstext
	sta $b2
	stx $b3
	rts


; interrupts
	
irqs1	inc $d019

; set sprites to no-expand , no > 256
	lda #0
	sta $d01d	; sprites no x-expand

	lda #0
	sta $d010
;
	
	
	lda ruchaczkolor
	;lda blfadein,x
	
	sta $d027
	sta $d028
	sta $d029
	sta $d02a
	sta $d02b
	sta $d02c
	sta $d02d
	sta $d02e


;
	lda #88
	sta $D012
	lda $d011
	and #127
	sta $d011

	lda #<irqs2
	ldy #>irqs2
	sta $0314
	sty $0315
if debug=1
	inc $d020
eif

	lda doups
	beq _jupia
	jsr moveup
	jsr dodajlinie
	lda #0
	sta doups
_jupia
	

;;;;;;;;;;;;; scroll subroutine

; scroll @ 12-13 Y charline

if debug = 1 
	inc $d020
eif

.include scrollirq.asm

if debug = 1 
	dec $d020
eif

;;;;;;;;;;;;;;;;

	clc
	lda #50
	sta $d001
	sta $d003
	sta $d005
	sta $d007
	lda #71
	sta $d009
	sta $d00b
	sta $d00d
	sta $d00f

	lda #140
	sta $d000
	adc #24
	sta $d002
	adc #24
	sta $d004
	adc #24
	sta $d006

	lda #140
	sta $d008
	adc #24
	sta $d00a
	adc #24
	sta $d00c
	adc #24
	sta $d00e

	ldx sprusd
	lda sprtab,x
	tay
	sty $6c00-8
	iny
	sty $6c00-7
	iny
	sty $6c00-6
	iny
	sty $6c00-5
	iny
	sty $6c00-4
	iny
	sty $6c00-3
	iny
	sty $6c00-2
	iny
	sty $6c00-1

if debug = 1 
	dec $d020
eif

	 jmp irqex

irqs2	inc $d019


	lda #132	; was 132
	sta $D012
	lda $d011
	and #127
	sta $d011

	lda #<irqs3
	ldy #>irqs3
	sta $0314
	sty $0315

if debug = 1 
	inc $d020
eif
	clc
	lda #92
	sta $d001
	sta $d003
	sta $d005
	sta $d007
	lda #113
	sta $d009
	sta $d00b
	sta $d00d
	sta $d00f

	lda #140
	sta $d000
	adc #24
	sta $d002
	adc #24
	sta $d004
	adc #24
	sta $d006

	lda #140
	sta $d008
	adc #24
	sta $d00a
	adc #24
	sta $d00c
	adc #24
	sta $d00e

	ldx sprusd
	lda sprtab,x
	clc
	adc #8
	tay
	sty $6c00-8
	iny
	sty $6c00-7
	iny
	sty $6c00-6
	iny
	sty $6c00-5
	iny
	sty $6c00-4
	iny
	sty $6c00-3
	iny
	sty $6c00-2
	iny
	sty $6c00-1

	


if debug=1
	dec $d020
eif

;;;;;;;;

	lda skrol   ; do skrola
	sta $d016


	 jmp irqex

irqs3	inc $d019


	lda #48+8*15
	sta $D012
	lda $d011
	and #127
	sta $d011

	lda #<irqs4
	ldy #>irqs4
	sta $0314
	sty $0315
;if debug=1
;	inc $d020
;eif


	ldx sprusd
	lda sprtab,x
	clc
	adc #16
	tay
	sty $6c00-8
	iny
	sty $6c00-7
	iny
	sty $6c00-6
	iny
	sty $6c00-5
;	iny

	clc
	lda #134
	sta $d001
	sta $d003
	sta $d005
	sta $d007

; this is unused actuially
;	lda #113
;	sta $d009
;	sta $d00b
;	sta $d00d
;	sta $d00f
;;; till here

	lda #140
	sta $d000
	adc #24
	sta $d002
	adc #24
	sta $d004
	adc #24
	sta $d006
;usunesd

;	lda #100
;	sta $d008
;	adc #24
;	sta $d00a
;	adc #24
;	sta $d00c
;	adc #24
;	sta $d00e

;; till here


; unused  (timing purposes)

;	sty $6c00-4
;	iny
;	sty $6c00-3
;	iny
;	sty $6c00-2
;	iny
;	sty $6c00-1

; end of shit



	dec sprw8
	LDA sprw8
	bne sprskip
	lda #10
	sta sprw8
	inc sprusd
	lda sprusd
	cmp #6
	bne sprskip
	lda #0
	sta sprusd
sprskip

	jsr $1003

	
	lda #255 
	sta $d01d	; x expand all sprites

	lda #64+32
	sta $d010 	; x-sprite > 256 for 5/6 of 7 sprites 

	ldy #152
	sty $6c00-8
	sty $6c00-7
	sty $6c00-6
	sty $6c00-5
	sty $6c00-4
	sty $6c00-3
	sty $6c00-2
	sty $6c00-1

	; starting X offest at 24 , Y at 50
	
	lda #48+16*8
	sta $d001
	sta $d003
	sta $d005	
	sta $d007
	sta $d009
	sta $d00b
	sta $d00d	
	sta $d00f

	clc
	lda #24

	sta $d000
	adc #48		;72
	sta $d002
	adc #48		;120
	sta $d004
	adc #48		;168
	sta $d006
	adc #48		;216
	sta $d008	
	;adc #48		
	lda #8		; 256+8  / x-expand
	sta $d00a
	adc #48		;256+56
	sta $d00c
	
	

;if debug=1
;	dec $d020
;eif
	 jmp irqex


irqs4
	inc $d019


	lda #0
	sta $d027
	sta $d028
	sta $d029
	sta $d02a
	sta $d02b
	sta $d02c
	sta $d02d
;	sta $d02e

	lda #$ff
	sta $D012
	lda $d011
	and #127
;	ora #128
	sta $d011

	lda #<irqs1
	ldy #>irqs1
	sta $0314
	sty $0315

if debug=1
	dec $d020
eif
	;inc $6800+24*40+20

	lda #$8
	sta $d016

	lda $d011
	and #255-4-2-1-8
	ora vpos
	sta $d011

	lda $dc01
	cmp #223
	bne _zaw

	jmp irqex

_zaw	dec dosc
	beq _Zaw2
	jmp irqex
	
_Zaw2	
	lda #4
	sta dosc
	
	dec vpos
	bpl irqd
	jsr resetvpos
	
irqd	
	


if debug=1
	inc $d020
eif
	
	jmp irqex
	
resetvpos
	inc doups
;	jsr moveup
	lda #7
	sta vpos
;	jsr writed011
	
	rts	

dodajlinie

;	inc $d020

	ldy #0
petlix	lda ($b2),y
	sta tempchar
	
	cmp #64
	bne dalii

	jmp lineskip
	
	
dalii	lda tempchar
	bne walwekran2
	jsr scrollsetup2
	jmp dalejs2
walwekran2 	
	sta $6800+24*40,y
	iny
	cpy #40
	bne petlix
	
	clc
	lda $b2
	adc #40
	sta $b2
	bcc dali
	inc $b3	
dali	
	
dalejs2	

;	dec $d020
	rts

tempchar .byte 0

vpos .byte 1
doups .byte 0

lineskip
	lda #32
	ldy 39
xxt	sta $6800+24*40,y
	dey
	bne xxt

	clc
	lda $b2
	adc #1
	sta $b2
	bcc dali
	inc $b3	

	rts ; jmp dalejs2

_exxit


